﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using Chefbook.DataObjects;
using NUnit.Framework;
using Rhino.Mocks;
using Chefbook.DataAccessLayer;
using Chefbook.UserActions;

namespace UnitTests.UserActionsTests
{
    [TestFixture]
    public class MoveCategoryActionFixture
    {
        private MockRepository mocks;
        private IUserAction action;
        private Category category, oldParent, newParent;
        private ChefbookEntities db;

        [SetUp]
        public void Init()
        {
            mocks = new MockRepository();
            db = new ChefbookEntities();

            oldParent = new Category();
            newParent = new Category();
            category = new Category();
            Assert.AreEqual(2, oldParent.Subcategories.Count);
            Assert.Contains(category, oldParent.Subcategories.ToList());
            Assert.AreEqual(0, newParent.Subcategories.Count);

            action = new MoveCategoryAction(category,newParent) { DatabaseConnector = db };
        }

        [Test]
        public void DoActionTest()
        {
            action.DoAction();
            Assert.AreEqual(1, oldParent.Subcategories.Count);
            Assert.Contains(category, newParent.Subcategories.ToList());
            Assert.False(oldParent.Subcategories.Contains(category));
            Assert.AreEqual(1, newParent.Subcategories.Count);
        }

        [Test]
        public void UndoActionTest()
        {
            action.DoAction();
            action.UndoAction();
            Assert.AreEqual(2, oldParent.Subcategories.Count);
            Assert.Contains(category, oldParent.Subcategories.ToList());
            Assert.AreEqual(0, newParent.Subcategories.Count);
        }

        [Test]
        public void UndoActionWithoutDoingTest()
        {
            UserActionTestsHelper.UndoActionWithoutDoingTest(action);
        }

        [Test]
        public void UndoActionTwiceAfterDoingTest()
        {
            UserActionTestsHelper.UndoActionTwiceAfterDoingTest(action);
        }

        [Test]
        public void DoActionTwiceTest()
        {
            UserActionTestsHelper.DoActionTwiceTest(action);
        }

        [Test]
        public void ActionNameTest()
        {
            Assert.AreEqual(string.Format("Move Category '{0}' from '{1}' to '{2}'", category, oldParent, newParent), action.ToString());
        }
    }
}
